﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace Axiom.Hermetica.WPF
{
	public partial class MainWindow : Window
	{
		public MainWindow()
		{
			InitializeComponent();
		}

		private void OnLoaded(object sender, RoutedEventArgs e)
		{
			App.Model.Load();
		}

		private bool _allowDirectNavigation = true;
		private NavigatingCancelEventArgs _navArgs = null;
		private Duration _duration = new Duration(TimeSpan.FromMilliseconds(140));
		private double _oldHeight = 0;

		private void frame_Navigating(object sender, NavigatingCancelEventArgs e)
		{
			//if (Content != null && !_allowDirectNavigation)
			//{
			//	e.Cancel = true;

			//	_navArgs = e;
			//	_oldHeight = frame.ActualHeight;

			//	DoubleAnimation animation0 = new DoubleAnimation();
			//	animation0.From = frame.ActualHeight;
			//	animation0.To = 0;
			//	animation0.Duration = _duration;
			//	animation0.Completed += SlideCompleted;
			//	frame.BeginAnimation(HeightProperty, animation0);
			//}
			//_allowDirectNavigation = false;
		}

		private void SlideCompleted(object sender, EventArgs e)
		{
			//_allowDirectNavigation = true;
			//switch (_navArgs.NavigationMode)
			//{
			//	case NavigationMode.New:
			//		if (_navArgs.Uri == null)
			//			frame.Navigate(_navArgs.Content);
			//		else
			//			frame.Navigate(_navArgs.Uri);
			//		break;
			//	case NavigationMode.Back:
			//		frame.GoBack();
			//		break;
			//	case NavigationMode.Forward:
			//		frame.GoForward();
			//		break;
			//	case NavigationMode.Refresh:
			//		frame.Refresh();
			//		break;
			//}

			//Dispatcher.BeginInvoke(DispatcherPriority.Loaded, (ThreadStart)delegate()
			//{
			//	DoubleAnimation animation0 = new DoubleAnimation();
			//	animation0.From = 0;
			//	animation0.To = _oldHeight;
			//	animation0.Duration = _duration;
			//	frame.BeginAnimation(HeightProperty, animation0);
			//});
		}

		private void OnCatalogue(object sender, RoutedEventArgs e)
		{
			var uri = new Uri(@"\Views\MainPage.xaml", UriKind.Relative);
			frame.NavigationService.Navigate(uri);
		}

		private void OnLibrary(object sender, RoutedEventArgs e)
		{
			var uri = new Uri(@"\Views\LibraryPage.xaml", UriKind.Relative);
			frame.NavigationService.Navigate(uri);
		}
	}
}
